package com.example.kcb;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Lenovo on 2018/12/1.
 */

public class AddCourseActivity extends AppCompatActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_course);
        setFinishOnTouchOutside(false);
        final Spinner periodSpinner = (Spinner) findViewById(R.id.periods_spinner);
        final Spinner daySpinner = (Spinner) findViewById(R.id.day_spinner);
        final Spinner classSpinner = (Spinner) findViewById(R.id.class_spinner);
        Button backButton = (Button) findViewById(R.id.back_add);
        backButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        Button okButton = (Button) findViewById(R.id.button);
        okButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                String courseName = inputCourseName.getText().toString();
//                String teacher = inputTeacher.getText().toString();
//                String classRoom = inputClassRoom.getText().toString();
                String period = periodSpinner.getSelectedItem().toString();
//                String start = inputStart.getText().toString();
//                String end = inputEnd.getText().toString();
                int day = daySpinner.getSelectedItemPosition() + 1;  // 获取选中的星期几
                String classRoom = classSpinner.getSelectedItem().toString();
//                String week = inputWeek.getSelectedItem().toString();

                if (period.equals("")) {
                    Toast.makeText(AddCourseActivity.this, "基本课程信息未填写", Toast.LENGTH_SHORT).show();
                } else {
                    Course course = new Course("化学", "李惠惠", classRoom,day, period);
                    Intent intent = new Intent(AddCourseActivity.this, MainActivity.class);
                    intent.putExtra("course", course);
                    setResult(0, intent);
                    finish();
                }
            }
        });
    }
}
